package com.demo2do.fms.admin.dao.data;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.data.MasterData;
import com.demo2do.fms.entity.data.business.VehicleFeature;

/**
 * @author Ysy
 */
@Dao("hibernate")
public interface MasterDataDao {
    
    /**
     * get master_data value by type and id
     * 
     * @param type
     * @param id
     * @return
     */
    @Query("SELECT value FROM MasterData WHERE type = :type and code = :id")
    public String get(@Variable("type")String type, @Variable("id") Long id);
    
    /**
     * 
     * @param oilTypeId
     * @return
     */
    @Query("SELECT value FROM MasterData WHERE type IN ('OIL_OUTSIDE','OIL_INSIDE') AND code = :oilType")
    public String getOilType(@Variable("oilType") Long oilTypeId);
    
    /**
     * list all master_data
     * 
     * @return
     */
    @Query("FROM MasterData")
    public List<MasterData> list();
    
    /**
     * list master_data by type
     * 
     * @param type
     * @return
     */
    @Query("FROM MasterData WHERE type = :type")
    public List<MasterData> list(@Variable("type") String type);
    
    /**
     * list oil type
     * 
     * @return
     */
    @Query("FROM MasterData data WHERE data.type = 'OIL_OUTSIDE' or data.type = 'OIL_INSIDE' ORDER BY data.code DESC")
    public List<MasterData> listOilType();
    
    /**
     * list shipment status
     * 
     * @return
     */
    @Query("FROM MasterData data WHERE data.type = 'SHIPMENT_STATUS' AND data.code <=3 ORDER BY data.code DESC")
    public List<MasterData> listShipmentStatus();
    
    /**
     * list all VehicleFeature
     * 
     * @return
     */
    @Query("FROM VehicleFeature  WHERE disabled = false ORDER BY name ASC")
    public List<VehicleFeature> listVehicleFeature();
    
}
